package com.CNMedical.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.CNMedical.common.annotation.Log;
import com.CNMedical.common.core.controller.BaseController;
import com.CNMedical.common.core.domain.AjaxResult;
import com.CNMedical.common.enums.BusinessType;
import com.CNMedical.system.domain.entity.AppletLearningHistory;
import com.CNMedical.system.service.IAppletLearningHistoryService;
import com.CNMedical.common.utils.poi.ExcelUtil;
import com.CNMedical.common.core.page.TableDataInfo;

/**
 * 学习历史Controller
 * 
 * @author tang
 * @date 2023-03-28
 */
@RestController
@RequestMapping("/system/history")
public class AppletLearningHistoryController extends BaseController
{
    @Autowired
    private IAppletLearningHistoryService appletLearningHistoryService;

    /**
     * 查询学习历史列表
     */
    @PreAuthorize("@ss.hasPermi('system:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletLearningHistory appletLearningHistory)
    {
        startPage();
        List<AppletLearningHistory> list = appletLearningHistoryService.selectAppletLearningHistoryList(appletLearningHistory);
        return getDataTable(list);
    }

    /**
     * 导出学习历史列表
     */
    @PreAuthorize("@ss.hasPermi('system:history:export')")
    @Log(title = "学习历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppletLearningHistory appletLearningHistory)
    {
        List<AppletLearningHistory> list = appletLearningHistoryService.selectAppletLearningHistoryList(appletLearningHistory);
        ExcelUtil<AppletLearningHistory> util = new ExcelUtil<AppletLearningHistory>(AppletLearningHistory.class);
        util.exportExcel(response, list, "学习历史数据");
    }

    /**
     * 获取学习历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appletLearningHistoryService.selectAppletLearningHistoryById(id));
    }

    /**
     * 新增学习历史
     */
    @PreAuthorize("@ss.hasPermi('system:history:add')")
    @Log(title = "学习历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletLearningHistory appletLearningHistory)
    {
        return toAjax(appletLearningHistoryService.insertAppletLearningHistory(appletLearningHistory));
    }

    /**
     * 修改学习历史
     */
    @PreAuthorize("@ss.hasPermi('system:history:edit')")
    @Log(title = "学习历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletLearningHistory appletLearningHistory)
    {
        return toAjax(appletLearningHistoryService.updateAppletLearningHistory(appletLearningHistory));
    }

    /**
     * 删除学习历史
     */
    @PreAuthorize("@ss.hasPermi('system:history:remove')")
    @Log(title = "学习历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appletLearningHistoryService.deleteAppletLearningHistoryByIds(ids));
    }
}
